package mulMan.gui.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;

import mulMan.domain.AudioFileFactory;
import mulMan.domain.AudioFileModel;
import mulMan.domain.PlaylistModel;
import mulMan.gui.view.AddFileView;
import mulMan.gui.view.AudioFilesView;
import mulMan.gui.view.PlaylistView;

public class PlaylistController extends Observable{
	
	private PlaylistModel playlist;
	private PlaylistView view;
	
	
	public PlaylistModel getPlaylist() {
		return playlist;
	}
	public void setPlaylist(PlaylistModel playlist) {
		this.playlist = playlist;
	}

	public PlaylistView getView() {
		return view;
	}
	public void setView(PlaylistView view) {
		this.view = view;
	}
	
	
	public PlaylistController(PlaylistModel playlist, PlaylistView view) {
		this.playlist = playlist;
		this.view = view;
		
		addAudioFilesView();
		view.addAddNewAudioFileListener(new AddNewAudioFileListener());
		view.addExitListener(new ExitListener());
	}
	
	public void addAudioFilesView() {
		AudioFilesView audioFilesView = new AudioFilesView(playlist.getAudioFilesModels());
		new AudioFilesController(playlist.getAudioFilesModels(), audioFilesView);
		view.setAudioFilesView(audioFilesView);
	}
	
	
	//ACTION LISTENERS
	
	class AddNewAudioFileListener implements ActionListener {

		public void actionPerformed(ActionEvent arg0) {
			AudioFileFactory audioFileFacory = new AudioFileFactory(playlist);
			AudioFileModel audioFileModel = audioFileFacory.addAudioFileToPlaylist();
			
			new AudioFileController(audioFileModel, new AddFileView(audioFileModel));
		}
		
	}
	
	class ExitListener implements ActionListener {

		public void actionPerformed(ActionEvent arg0) {
			System.exit(0);
		}
		
	}
}
